﻿using System;
using System.Collections.Generic;

namespace TraceThisItem.Domain
{
	public class Item
	{
		#region Properties

		public int Id { get; set; }

		public byte Priority { get; set; }

		public string Subject { get; set; }

		public string Comments { get; set; }

		public string Description { get; set; }

		public DateTime CreatedOn { get; set; }

		public DateTime LatestUpdate { get; set; }

		public int TeamId { get; set; }

		#endregion Properties

		#region Navigation properties

		public virtual ICollection<ItemStatus> Traceability { get; set; }

		public virtual Team Team { get; set; }

		public virtual ItemType Type { get; set; }

		public virtual Project Project { get; set; }

		#endregion Navigation properties

		#region Display properties
		public string CurrentStatus  //HZ: La agregue para mostrar el estado actual de una tarea en Default.aspx (el de Ver mis incidencias)
		{
			get
			{
				ItemStatus lastItemStatus = null;
				foreach (ItemStatus itemStatus in this.Traceability)
				{
					lastItemStatus = itemStatus;
				}

				return lastItemStatus.StatusNode.Name;
			}
		}
		public int CurrentStatusId
		{
			get
			{
				ItemStatus lastItemStatus = null;
				foreach (ItemStatus itemStatus in this.Traceability)
				{
					lastItemStatus = itemStatus;
				}

				return lastItemStatus.StatusNode.Id;
			}
		}
		public string CurrentResponsible  //HZ: La agregue para mostrar el estado actual de una tarea en Default.aspx (el de Ver mis incidencias)
		{
			get
			{
				ItemStatus lastItemStatus = null;
				foreach (ItemStatus itemStatus in this.Traceability)
				{
					lastItemStatus = itemStatus;
				}

				return lastItemStatus.Responsible.FullName;
			}
		}
		public string CurrentPriority
		{
			get
			{
				switch (this.Priority)
				{
					case (int)ItemPriority.Alta:
						return "Alta";
					case (int)ItemPriority.Media:
						return "Normal";
					case (int)ItemPriority.Baja:
						return "Baja";
					default:
						throw new NotImplementedException("No existe la codificación para la prioridad " + this.Priority.ToString().PadLeft(2, '0'));
				}
			}
		}
		#endregion

		#region Constructor

		public Item() { }

		#endregion Constructor


	}
}